package com.atguigu.cmsservice.controller;


import com.atguigu.cmsservice.entity.CrmBanner;
import com.atguigu.cmsservice.service.CrmBannerService;
import com.atguigu.common_uitls.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 首页banner表 前端控制器
 * </p>
 *
 * @author wzh
 * @since 2022-10-02
 */
@CrossOrigin
@RestController
@RequestMapping("/educms/banneradmin")
public class BannerAdminController {
    @Autowired
    private CrmBannerService crmBannerService;
    //查询banner内容
    @GetMapping("pageBanner/{page}/{limit}")
    public R pageBanner(@PathVariable String page,@PathVariable String limit){
        Page<CrmBanner> bannerPage=new Page<>();
        crmBannerService.page(bannerPage,null);
        return R.ok().data("items",bannerPage.getRecords()).data("total",bannerPage.getTotal());
    }
    @PostMapping("addBanner")
    public R addBanner(@RequestBody CrmBanner banner){
        crmBannerService.save(banner);
        return R.ok();
    }
    @GetMapping("get/{id}")
    public R getBanner(@PathVariable String id){
        CrmBanner byId = crmBannerService.getById(id);
        return R.ok().data("item",byId);
    }

    @PutMapping("update")
    public R updateBanner(@RequestBody CrmBanner crmBanner){
        crmBannerService.updateById(crmBanner);
        return R.ok();
    }
}

